home *** CD-ROM | disk | FTP | other *** search
- /*
- This Setup Function calls the System 7 PBCatSearch routine to search for the first
- SimpleText application found on the default volume. If a copy of the application is
- found, the folder's FSSpec is returned to the Installer to be considered for the
- suggested installation folder.
-
- This function does nothing under pre-7.0 systems.
-
- You can use the accompanying routines to display information in the Installer Debugger
- to help you learn and debug your Setup Function.
-
- */
-
- #ifndef __Files__
- #include <Files.h>
- #endif
-
- #ifndef __GestaltEqu__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __Memory__
- #include <Memory.h>
- #endif
-
- #ifndef __OSUtils__
- #include <OSUtils.h>
- #endif
-
- #ifndef __Packages__
- #include <Packages.h>
- #endif
-
- #ifndef __InstallerScript__
- #include "InstallerScript.h"
- #endif
-
- #ifndef __ActionHandlerHeader__
- #include "ActionHandlerHeader.h"
- #endif
-
- #include <TextUtils.h>
-
-
- void DisplayPreferenceInfo( EnvironmentSetupPBPtr pSetupPBPtr, long pResultCode );
-
- long SetupFunction( EnvironmentSetupPBPtr pSetupPBPtr )
- {
-
- #define kOptBufferSize 0x4000
-
- long theResult = 0;
- long theSysVersionNum;
- OSErr theErr;
- CInfoPBRec theFirstSearchCriteria;
- CInfoPBRec theSecondSearchCriteria;
- CSParam theCatParamBlock;
- FSSpec theMatchedFSSpec;
- long theMaxNumOfMatches = 1;
- char *theOptionalBuffer=NewPtr(kOptBufferSize);
- CInfoPBRec theCatInfoParamBlock;
- Str255 theTempStr255;
- short theByteCtr;
-
-
- // If you want to select the default target volume and/or system disk set these fields
-
- Gestalt( 'sysv', &theSysVersionNum );
- if( theSysVersionNum >= 0x00000700 ) {
-
- theCatParamBlock.ioCompletion = NULL;
- theCatParamBlock.ioNamePtr = NULL;
- theCatParamBlock.ioVRefNum = pSetupPBPtr->fTargetFSSpec.vRefNum;
-
- theCatParamBlock.ioMatchPtr = (FSSpecArrayPtr)&theMatchedFSSpec; /* match array */
- theCatParamBlock.ioReqMatchCount = theMaxNumOfMatches; /* maximum allowable matches */
- theCatParamBlock.ioSearchBits = fsSBFlFndrInfo + fsSBFlAttrib; /* search criteria selector */
- theCatParamBlock.ioSearchInfo1 = &theFirstSearchCriteria; /* search values and range lower bounds */
- theCatParamBlock.ioSearchInfo2 = &theSecondSearchCriteria; /* search values and range upper bounds */
- theCatParamBlock.ioSearchTime = 0; /* length of time to run search */
- theCatParamBlock.ioCatPosition.initialize = 0; /* current position in the catalog */
- theCatParamBlock.ioOptBuffer = theOptionalBuffer; /* optional performance enhancement buffer */
- theCatParamBlock.ioOptBufSize = kOptBufferSize; /* size of buffer pointed to by ioOptBuffer */
-
- theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdType = 'APPL';
- theFirstSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator = 'ttxt';
- theFirstSearchCriteria.hFileInfo.ioFlAttrib = 0x00;
-
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdType = 0xFFFFFFFF; /*the type of the file*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdCreator = 0xFFFFFFFF; /*file's creator*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFlags = 0x0000; /*flags ex. hasbundle,invisible,locked, etc.*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.h = 0x0000; /*file's location in folder*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdLocation.v = 0x0000; /*file's location in folder*/
- theSecondSearchCriteria.hFileInfo.ioFlFndrInfo.fdFldr = 0x0000; /*folder containing file*/
- theSecondSearchCriteria.hFileInfo.ioFlAttrib = 0x10;
-
- theErr = PBCatSearchSync( &theCatParamBlock );
-
- if( theErr == noErr && theCatParamBlock.ioActMatchCount >= 1 ) {
-
- theCatInfoParamBlock.dirInfo.ioNamePtr = (StringPtr)&theTempStr255;
- theCatInfoParamBlock.dirInfo.ioVRefNum = theMatchedFSSpec.vRefNum;
- theCatInfoParamBlock.dirInfo.ioFDirIndex = -1;
- theCatInfoParamBlock.dirInfo.ioDrDirID = theMatchedFSSpec.parID;
- theErr = PBGetCatInfoSync( &theCatInfoParamBlock );
-
- if( theErr == noErr ) {
- pSetupPBPtr->fTargetFSSpec.vRefNum = theCatInfoParamBlock.dirInfo.ioVRefNum;
- pSetupPBPtr->fTargetFSSpec.parID = theCatInfoParamBlock.dirInfo.ioDrParID;
-
- for( theByteCtr = 0; theByteCtr <= theCatInfoParamBlock.dirInfo.ioNamePtr[0]; theByteCtr++ )
- pSetupPBPtr->fTargetFSSpec.name[theByteCtr] = theCatInfoParamBlock.dirInfo.ioNamePtr[theByteCtr];
- }
- DisposePtr(theOptionalBuffer);
- }
-
- }
- else {
-
- // Implement the pre-7.0 search code here
-
- }
-
- DisplayPreferenceInfo( pSetupPBPtr, theResult );
- return theResult;
- }
-
-
- // -------------------------------------------------------------------------------------------------------------------------------------
- // The routines below are for displaying the contents of the parameter block passed to the Setup Function.
- // Call DisplayPreferenceInfo to write this information to the Installer Debugger.
-
- void MakeFilePath( FSSpec* pFileFSSpec, Str255 pFilePath )
- {
-
- CInfoPBRec cPBRec;
- Str255 directoryName = "";
- short i;
- OSErr theErr;
-
- // Get the file name
- for( i=0;i<=pFileFSSpec->name[0];i++)
- pFilePath[i] = pFileFSSpec->name[i];
-
- cPBRec.hFileInfo.ioCompletion = NULL;
- cPBRec.hFileInfo.ioNamePtr = directoryName;
- cPBRec.hFileInfo.ioFDirIndex = -1;
- cPBRec.hFileInfo.ioDirID = pFileFSSpec->parID;
- cPBRec.hFileInfo.ioVRefNum = pFileFSSpec->vRefNum;
- theErr = PBGetCatInfo( &cPBRec, 0 );
-
- // Preappend directoryName
- BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
- for( i=1;i<=directoryName[0];i++)
- pFilePath[i] = directoryName[i];
- pFilePath[i] = ':';
- pFilePath[0] += directoryName[0] + 1;
-
- while ( theErr == noErr && cPBRec.dirInfo.ioDrParID != 1 && pFilePath[0] + directoryName[0] + 1 < 255 ) {
-
- // Preappend directoryName
- cPBRec.hFileInfo.ioDirID = cPBRec.dirInfo.ioDrParID;
- cPBRec.hFileInfo.ioFDirIndex = -1;
- theErr = PBGetCatInfo( &cPBRec, 0 );
-
- if( theErr == noErr ) {
- // Preappend directoryName
- BlockMove( pFilePath + 1, pFilePath + directoryName[0] + 2, pFilePath[0] );
- for( i=1;i<=directoryName[0];i++)
- pFilePath[i] = directoryName[i];
- pFilePath[i] = ':';
- pFilePath[0] += directoryName[0] + 1;
- }
- }
-
- }
-
- void PrintLine( InstallerCallBackUPP pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
- {
- long theResult;
- RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );
- }
-
- void DisplayPreferenceInfo( EnvironmentSetupPBPtr pSetupPBPtr, long pResultCode )
- {
-
- StringPtr kBeginCallPart1 = "\p=>========================== Begin Setup Function Call ====";
- StringPtr kBeginCallPart3 = "\p==================================================";
-
- StringPtr kEndCallPart1 = "\p-<-------------------------- End Setup Function Call ------ ";
- StringPtr kEndCallPart3 = "\p ----------------------------\n";
-
- StringPtr kResultText = "\pResult Code: ";
-
- StringPtr kTargetFolderPathText = "\p Target Folder Path: ";
- StringPtr kSystemDiskText = "\p System Disk Name: ";
-
- Str255 tempNumStr;
- Str255 tempStr255;
- FSSpec tempFSSpec;
-
- // -- Beginning line
- PrintLine( pSetupPBPtr->fCallBackProcPtr, kBeginCallPart1, kBeginCallPart3, "\p", "\p" );
-
- // -- Target Folder Path
- MakeFilePath( &(pSetupPBPtr->fTargetFSSpec), tempStr255 );
- PrintLine( pSetupPBPtr->fCallBackProcPtr, kTargetFolderPathText, tempStr255, "\p", "\p" );
-
- // —— System Disks Name
- tempFSSpec.name[0] = 0;
- tempFSSpec.parID = 2;
- tempFSSpec.vRefNum = pSetupPBPtr->fSystemVRefNum;
- MakeFilePath( &tempFSSpec, tempStr255 );
- PrintLine( pSetupPBPtr->fCallBackProcPtr, kSystemDiskText, tempStr255, "\p", "\p" );
-
- // -- Ending line
- NumToString( pResultCode, tempNumStr );
- PrintLine( pSetupPBPtr->fCallBackProcPtr, kEndCallPart1, kResultText, tempNumStr, kEndCallPart3 );
- }
-
- #include "InstallerCallbackGlue.c"
-